<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="libs/js/vue.js"></script>
    <script src="libs/js/vue-router.js"></script>
</head>
<body>
    <div id="app">
        <router-link to="/account">Account</router-link>
        <router-view></router-view>
    </div>

    <template id="templ">
        <div>
            <h1> 这是一个 ACCOUNT 组件 </h1>
            <router-link to="/account/login">登录</router-link>
            <router-link to="/account/register">注册</router-link>

            <router-view></router-view>
        </div>
    </template>

    <script>

        // 组件的模板对象
        var account = {
            template: "#templ"
        }
        var login = {
            template: "<h3>登录</h3>"
        }
        var register = {
            template: "<h3>注册</h3>"
        }

        var routerObj = new VueRouter({
            routes: [
                {
                    path: "/account", 
                    component: account,
                    children: [ // 使用 children 实现子路由，同时子路由的 path 前不要带 /，
                        { path: "login", component: login },  // login 前不加 “/” ，否则以根路径开始解析
                        { path: "register", component: register }
                    ]
                },
                // {path: "/account/login", component: login},
                // {path: "/account/register", component: register}
            ]
        })

        var app = new Vue({
            el: "#app",
            data: {},
            router: routerObj
        })
    </script>
</body>
</html>